package com.sengled.cloud.biz.union.mgt.api.controller;

import com.sengled.cloud.biz.union.mgt.common.util.CurrentUserUtil;
import com.sengled.cloud.biz.union.mgt.model.request.GetRoleListRequest;
import com.sengled.cloud.biz.union.mgt.model.request.SaveShopAccountRequest;
import com.sengled.cloud.biz.union.mgt.model.request.ShopAccountPwdResetRequest;
import com.sengled.cloud.biz.union.mgt.model.request.ShopAccountRequest;
import com.sengled.cloud.biz.union.mgt.model.response.QueryRoleWithPage;
import com.sengled.cloud.biz.union.mgt.model.response.ResponseMessage;
import com.sengled.cloud.biz.union.mgt.model.response.ShopAccountResponse;
import com.sengled.cloud.biz.union.mgt.model.vo.ShopAccountPage;
import com.sengled.cloud.biz.union.mgt.service.sys.IShopAccountService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by csolo on 2017/11/15.
 */
@Controller
@RequestMapping(value = "/api/v1")
public class ShopAccountController {


    @Autowired
    private IShopAccountService shopAccountService;

    @ApiOperation(value = "测试查询角色账号请求", notes = "查询角色账号对象接口")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage<ShopAccountPage> getShopAccountList(@RequestBody ShopAccountRequest shopAccountRequest, HttpServletRequest request) {
        Long customerId = CurrentUserUtil.getCurrentAccountId(request);
        ResponseMessage<ShopAccountPage> rm = shopAccountService.listShopAccountByPage(shopAccountRequest,customerId);
        return rm;
    }

    @ApiOperation(value = "测试编辑角色账号请求", notes = "编辑角色账号请求")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount/edit/{id}", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseMessage<ShopAccountResponse> editShopAccount(@PathVariable Long id) {
        ResponseMessage<ShopAccountResponse> rm = shopAccountService.editShopAccount(id);
        return rm;
    }

    @ApiOperation(value = "测试查看店铺账号详情请求", notes = "查看店铺账号详情")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount/detail/{id}", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseMessage<ShopAccountResponse> shopAccountDetail(@PathVariable Long id) {
        ResponseMessage<ShopAccountResponse> rm = shopAccountService.shopAccountDetail(id);
        return rm;
    }

    @ApiOperation(value = "测试Save角色账号请求", notes = "Save角色账号请求")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount/save", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage saveShopAccount(@RequestBody SaveShopAccountRequest saveShopAccountRequest) {
        ResponseMessage rm = shopAccountService.saveShopAccount(saveShopAccountRequest);
        return rm;
    }

    @ApiOperation(value = "测试重置密码请求", notes = "重置密码请求")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount/pwd/reset", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage resetPwd(@RequestBody ShopAccountPwdResetRequest shopAccountPwdResetRequest) {
        ResponseMessage rm = shopAccountService.resetPwd(shopAccountPwdResetRequest.getId(),shopAccountPwdResetRequest.getNewPwd());
        return rm;
    }
/*
    @ApiOperation(value = "测试重置密码请求", notes = "重置密码请求")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "正常"),
            @ApiResponse(code = 10001, message = "系统错误"),
            @ApiResponse(code = 20002, message = "参数错误")
    })
    @RequestMapping(value = "/shopAccount/pwd/reset", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage resetPwd(@ApiParam(value = "店铺账号ID", required = true) @RequestBody Long id,@ApiParam(value = "新密码", required = true) @RequestBody String newPwd) {
        ResponseMessage rm = shopAccountService.resetPwd(id,newPwd);
        return rm;
    }
*/
}
